

const path = require('path');
const staticImg = path.join(__dirname, 'static');

function SensorbitUnoBlocks(Blockly) {
    var show_color = "#f59057";



    //lcd配置地址
Blockly.Blocks.microbit_lcdinit = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
      .appendField(Blockly.Msg.MICROBIT_LCDINIT_ADDRESS)
    this.appendValueInput("microbit_lcdinits", Number)
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };
  
  //lcd清屏
  Blockly.Blocks.microbit_lcdClear = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
    .appendField(Blockly.Msg.MICROBIT_LCDPRINT)
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };

  //lcd打开显示屏
  Blockly.Blocks.microbit_lcdScreen = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
    .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_LCDON, "on()"],
        [Blockly.Msg.MICROBIT_LCDOFF, "off()"]
    ]), "lcdScreen")
      .appendField(Blockly.Msg.MICROBIT_LCDSCREEN)
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };
  //lcd背光
  Blockly.Blocks.microbit_lcdBackLight = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
    .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_LCDON, "on()"],
        [Blockly.Msg.MICROBIT_LCDOFF, "off()"]
    ]), "lcdBackLight")
      .appendField(Blockly.Msg.MICROBIT_LCDBACKLIGHT)
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };


  //lcd移动
  Blockly.Blocks.microbit_lcdShift = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
    .appendField(Blockly.Msg.MICROBIT_LCDSHIFT)
    .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_LCDLEFT, "left()"],
        [Blockly.Msg.MICROBIT_LCDRIGHT, "right()"]
    ]), "lcdShift");
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };

  //lcd显示
  Blockly.Blocks.microbit_lcdposition = {
    init:function(){
        this.setColour(show_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_LCDSHOWROW)
        .appendField(Blockly.Msg.MICROBIT_ROW)
        this.appendValueInput("row", Number)
        this.appendDummyInput("")
        .appendField(Blockly.Msg.MICROBIT_COL)
        this.appendValueInput("col", Number)
        this.appendDummyInput("")
        .appendField(Blockly.Msg.MICROBIT_LCDSHOW)
        this.appendValueInput("lcdStr", String)
        
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
    }
  };


    return Blockly;
}

module.exports = SensorbitUnoBlocks;

